﻿using TI_BLE_HCI_ClientLib.BaseEntities;
using TI_BLE_HCI_ClientLib.GenericHCIEntities;
using TI_BLE_HCI_ClientLib.HCIBaseEntities;

namespace TI_BLE_HCI_ClientLib.HCICommands
{
    public class HCICommand_GAP_Set_Parameter : HCIVendorSpecificCommand
    {
        private const byte CMD = 0x30;

        public enum ParamIDEnum
        {
            TGAP_GEN_DISC_ADV_MIN = 0,  //!< Minimum time to remain advertising, when in Discoverable mode (mSec).  Setting this parameter to 0 turns off the timeout (default).
            TGAP_LIM_ADV_TIMEOUT = 1, //!< Maximum time to remain advertising, when in Limited Discoverable mode (mSec)
            TGAP_GEN_DISC_SCAN = 2, //!< Minimum time to perform scanning, when performing General Discovery proc (mSec)
            TGAP_LIM_DISC_SCAN = 3, //!< Minimum time to perform scanning, when performing Limited Discovery proc (mSec)
            TGAP_CONN_EST_ADV_TIMEOUT = 4, //!< Advertising timeout, when performing Connection Establishment proc (mSec)
            TGAP_CONN_PARAM_TIMEOUT = 5, //!< Link Layer connection parameter update notification timer, connection parameter update proc (mSec)
            TGAP_LIM_DISC_ADV_INT_MIN = 6, //!< Minimum advertising interval, when in limited discoverable mode (mSec)
            TGAP_LIM_DISC_ADV_INT_MAX = 7, //!< Maximum advertising interval, when in limited discoverable mode (mSec)
            TGAP_GEN_DISC_ADV_INT_MIN = 8, //!< Minimum advertising interval, when in General discoverable mode (mSec)
            TGAP_GEN_DISC_ADV_INT_MAX = 9, //!< Maximum advertising interval, when in General discoverable mode (mSec)
            TGAP_CONN_ADV_INT_MIN = 10, //!< Minimum advertising interval, when in Connectable mode (mSec)
            TGAP_CONN_ADV_INT_MAX = 11, //!< Maximum advertising interval, when in Connectable mode (mSec)
            TGAP_CONN_SCAN_INT = 12, //!< Scan interval used during Link Layer Initiating state, when in Connectable mode (mSec)
            TGAP_CONN_SCAN_WIND = 13, //!< Scan window used during Link Layer Initiating state, when in Connectable mode (mSec)
            TGAP_CONN_HIGH_SCAN_INT = 14, //!< Scan interval used during Link Layer Initiating state, when in Connectable mode, high duty scan cycle scan paramaters (mSec)
            TGAP_CONN_HIGH_SCAN_WIND = 15, //!< Scan window used during Link Layer Initiating state, when in Connectable mode, high duty scan cycle scan paramaters (mSec)
            TGAP_GEN_DISC_SCAN_INT = 16, //!< Scan interval used during Link Layer Scanning state, when in General Discovery proc (mSec)
            TGAP_GEN_DISC_SCAN_WIND = 17, //!< Scan window used during Link Layer Scanning state, when in General Discovery proc (mSec)
            TGAP_LIM_DISC_SCAN_INT = 18, //!< Scan interval used during Link Layer Scanning state, when in Limited Discovery proc (mSec)
            TGAP_LIM_DISC_SCAN_WIND = 19, //!< Scan window used during Link Layer Scanning state, when in Limited Discovery proc (mSec)
            TGAP_CONN_EST_ADV = 20, //!< Advertising interval, when using Connection Establishment proc (mSec)
            TGAP_CONN_EST_INT_MIN = 21, //!< Minimum Link Layer connection interval, when using Connection Establishment proc (mSec)
            TGAP_CONN_EST_INT_MAX = 22, //!< Maximum Link Layer connection interval, when using Connection Establishment proc (mSec)
            TGAP_CONN_EST_SCAN_INT = 23, //!< Scan interval used during Link Layer Initiating state, when using Connection Establishment proc (mSec)
            TGAP_CONN_EST_SCAN_WIND = 24, //!< Scan window used during Link Layer Initiating state, when using Connection Establishment proc (mSec)
            TGAP_CONN_EST_SUPERV_TIMEOUT = 25, //!< Link Layer connection supervision timeout, when using Connection Establishment proc (mSec)
            TGAP_CONN_EST_LATENCY = 26, //!< Link Layer connection slave latency, when using Connection Establishment proc (mSec)
            TGAP_CONN_EST_MIN_CE_LEN = 27, //!< Local informational parameter about min len of connection needed, when using Connection Establishment proc (mSec)
            TGAP_CONN_EST_MAX_CE_LEN = 28, //!< Local informational parameter about max len of connection needed, when using Connection Establishment proc (mSec)
            TGAP_PRIVATE_ADDR_INT = 29, //!< Minimum Time Interval between private (resolvable) address changes. In minutes (default 15 minutes).
            TGAP_SM_TIMEOUT = 30, //!< SM Message Timeout (milliseconds). Default 30 seconds.
            TGAP_SM_MIN_KEY_LEN = 31, //!< SM Minimum Key Length supported. Default 7.
            TGAP_SM_MAX_KEY_LEN = 32, //!< SM Maximum Key Length supported. Default 16.
            TGAP_GAP_TESTCODE = 33, //!< GAP TestCodes - puts GAP into a test mode
            TGAP_SM_TESTCODE = 34, //!< SM TestCodes - puts SM into a test mode
            TGAP_AUTH_TASK_ID = 35, //!< Task ID override for Task Authentication control
            TGAP_PARAMID_MAX = 36, //!< ID MAX-valid Parameter ID
            TGAP_GATT_TESTCODE = 100,  //!< GATT TestCodes - puts GATT into a test mode (paramValue maintained by GATT)
            TGAP_ATT_TESTCODE = 101  //!< ATT TestCodes - puts ATT into a test mode (paramValue maintained by ATT)
        }

        public enum Return_Status
        {
            Success = 0,
            InvalidParameter = 2
        }

        public HCICommand_GAP_Set_Parameter(ParamIDEnum paramID, ushort paramValue)
            : base(HCIVendorSpecificCommandCSG.GAP, CMD)
        {
            var pars = new BaseEntityParameter[2];

            pars[0] = new ByteParameter((byte)paramID);
            pars[1] = new WordParameter(paramValue);

            base.addParameters(pars);
        }
    }
}